package com.ct.system.start.controller;

import com.ct.common.utils.R;
import com.ct.system.start.service.QueryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("start/query")
public class QueryController {

    @Autowired
    private QueryService queryService;
    @Value("${title}")
    private String title;

    @GetMapping("/getTitle")
    public R getTitle(){
        return R.ok().put("data", title);
    }

    @GetMapping("/queryTemplate")
    public R queryTemplate(@RequestParam("nodeName")String nodeName){
        return queryService.queryTemplate(nodeName);
    }

    @GetMapping("/queryComponent")
    public R queryComponent(@RequestParam("dataClass")String dataClass){
        return queryService.queryComponent(dataClass);
    }

    @GetMapping("/queryClasses")
    public R queryClasses(@RequestParam("componentId")String componentId){
        return queryService.queryClasses(componentId);
    }

    @GetMapping("/queryClass")
    public R queryClass(@RequestParam("classId")String classId){
        return queryService.queryClass(classId);
    }

    @GetMapping("/queryClassesByTabName")
    public R queryClassesByTabName(@RequestParam("tabName")String tabName){
        return queryService.queryClassesByTabName(tabName);
    }


    @GetMapping("/queryPropertys")
    public R queryPropertys(@RequestParam("classId")String classId){
        return queryService.queryPropertys(classId);
    }

    @GetMapping("/queryEnums")
    public R queryEnums(@RequestParam("id")String id){
        return queryService.queryEnums(id);
    }

    @GetMapping("/queryTables")
    public R queryTables(@RequestParam("tableName")String tableName){
        return queryService.queryTables(tableName);
    }

    @GetMapping("/queryTableData")
    public R queryTableData(@RequestParam("tableName")String tableName,@RequestParam("pageSize")int pageSize,@RequestParam("currentPage")int currentPage){
        if(tableName != null && !"".equals(tableName) ){
            return queryService.queryTableData(tableName, pageSize, currentPage);
        }else{
            return R.ok();
        }
    }

}
